/**
 * 
 */
package gui.pop;

import gui.dialog.CommSendEMailDialog;
import gui.dialog.CommReadEMailDialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.example.www.communication.MailService.EMail;

/**
 * Menu PopUp para Utilizar en la lista de emails.
 * 
 * @author lito
 */
public class EMailPopUpMenu {
	private EMail		email;
	private Menu		swtmPopup;
	private MenuItem	swtmiRespond;
	private MenuItem	swtmiRead;
	
	public EMailPopUpMenu(Decorations parent, int style) {
		swtmPopup = new Menu(parent, style);
		parent.getShell().setMenu(swtmPopup);
		
		swtmiRespond = new MenuItem(swtmPopup, SWT.PUSH);
		swtmiRespond.setText("Respond");
		swtmiRespond.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent evt) {
				respondMenuItemWidgetSelected(evt);
			}
		});
		swtmiRespond
		.setImage(new Image(Display.getCurrent(),
				"resource/tango-icon-theme-0.8.90/16x16/actions/mail-reply-sender.png"));

		swtmiRead = new MenuItem(swtmPopup, SWT.PUSH);
		swtmiRead.setText("Read");
		swtmiRead.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent evt) {
				readMenuItemWidgetSelected(evt);
			}
		});
		swtmiRead
		.setImage(new Image(Display.getCurrent(),
				"resource/tango-icon-theme-0.8.90/16x16/actions/edit-find.png"));

	}
	
	public void setBoss(Control boss) {
		boss.setMenu(swtmPopup);
	}
	
	public void setEMail(EMail email) {
		this.email = email;
	}
	
	private void respondMenuItemWidgetSelected(SelectionEvent evt) {
		CommSendEMailDialog dialog = new CommSendEMailDialog(swtmPopup
				.getShell(), swtmPopup.getShell().getStyle());
		dialog.setEMailRecipient(email.getSender());
		dialog.open();
	}
	
	private void readMenuItemWidgetSelected(SelectionEvent evt) {
		CommReadEMailDialog dialog = new CommReadEMailDialog(swtmPopup
				.getShell(), swtmPopup.getShell().getStyle());
		dialog.setEmail(email);
		dialog.open();
	}
}
